    <?php  
    header("Content-type: text/html; charset=utf-8");  
              $goods_sn='C52-9027';
              $arr=explode('-',$goods_sn);
              if($arr){
                  $where="t3.prod_cls_num like '".$arr[0]."%".$arr[1]."'";
              }else{
                  $where="t3.prod_cls_num = '".$goods_sn."'";
              }
              
              try {  
                $hostname = "61.184.202.7"; 
                $port = "1433";  
                $dbname = "interlink";
                $username = "sa";  
                $pw = "interlink_*2017*";  
                $dbh = new PDO ("dblib:host=$hostname:$port;dbname=$dbname;charset=GBK","$username","$pw");  
              } catch (PDOException $e) {  
                echo "Failed to get DB handle: " . $e->getMessage() . "\n";  
                exit;  
              }
              $sql="select 
        t3.prod_cls_num
        ,t2.prod_num
        ,t3.prod_name 
        ,t4.color_num
        ,t4.color_name
        ,t5.spec_num 
        ,t5.spec_name
        ,t0.prod_id  
        ,sum(t0.stk_on_hand ) as'num'
        ,t3.std_unit_price 
        ,t3.pu_unit_price
        ,t7.description as 'lining'
        ,t9.description as 'season'
        ,t3.year_val
        ,t8.description as 'style'
        ,t6.description as 'category'
        
         from WAREH_STK t0 left join sys_unit t1 on t0.wareh_id = t1.unit_id
                           left join product t2 on t0.prod_id = t2.prod_id
                           left join prod_cls t3 on t2.prod_cls_id = t3.prod_cls_id
                           left join prod_color t4 on t2.color_id = t4.color_id
                           left join prod_spec t5 on t2.spec_id = t5.spec_id
                           left join prod_sort t6 on t3.prod_sort_id = t6.prod_sort_id
                           left join sys_code_dtl t7 on t3.out_mtrl = t7.code and t7.code_type = 'out_mtrl'
                           left join sys_code_dtl t8 on t3.brand  = t8.code and t8.code_type = 'brand' 
                           left join sys_code_dtl t9 on t3.season  = t9.code and t9.code_type = 'season' 
         where ".$where."  
         group by t3.prod_cls_num,t2.prod_num ,t3.prod_name,t4.color_num ,t4.color_name ,t5.spec_num,t5.spec_name,t0.prod_id ,t3.std_unit_price,t3.pu_unit_price 
         ,t6.description ,t3.year_val,t7.description,t8.description ,t9.description";
              $stmt = $dbh->prepare($sql);
              $stmt->execute();
              $total_num=0;
              while ($row = $stmt->fetch()) { 
                print_r($row);
                var_dump("nihao");
               /* $arr['prod_name']= iconv('GBK', 'UTF-8', $row['prod_name']); 
                $arr['color_name']= iconv('GBK', 'UTF-8', $row['color_name']); 
                $arr['lining']= iconv('GBK', 'UTF-8', $row['lining']); 
                $arr['season']= iconv('GBK', 'UTF-8', $row['season']); 
                $arr['style']= iconv('GBK', 'UTF-8', $row['style']); 
                $arr['category']= iconv('GBK', 'UTF-8', $row['category']); 
                $arr['prod_cls_num']=$row['prod_cls_num'];
                $arr['prod_num']=$row['prod_num'];
                $arr['color_num']=$row['color_num'];
                $arr['spec_num']=$row['spec_num'];
                $arr['spec_name']=iconv('GBK', 'UTF-8', $row['spec_name']);
                $arr['std_unit_price']=$row['std_unit_price'];
                $arr['pu_unit_price']=$row['pu_unit_price'];
                $arr['year_val']=$row['year_val'];
                $arr['num']=$row['num'];
                $total_num+=$arr['num'];
                $datas['data'][]=$arr;
                $color[]=$arr['color_name'];
                $spec[]=$arr['spec_name'];*/
                  
              }
              //$datas['spec']=implode(',',$spec).',';
             // print_r($color);
             /* $datas['total_num']=$total_num;
              $datas['color']=implode(',',$color).',';
              $datas['spec']=implode(',',$spec).',';*/
              //echo json_encode($datas);
              unset($dbh); unset($stmt);
          
      
    ?>  
